﻿@page "/user_center/position"
@inherits ListOperateTableBase<PositionDto, int, PositionEdit,UserCenterResource>
@{
    TableFilter<string?>[] positionGradeFilters = DictHelper.GetCodesFromCache<PositionDto>(p => p.Grade)?.Select(x => { return new TableFilter<string?>() { Text = Localizer[x.CodeName], Value = x.CodeValue }; }).ToArray() ?? new TableFilter<string?>[0];
}
<div>
    <Table @ref="_table"
           TItem="PositionDto"
           DataSource="@_datas"
           Total="_total"
           OnChange="@OnChange"
           @bind-PageSize="_pageSize"
           @bind-PageIndex="_pageIndex"
           @bind-SelectedRows="_selectedRows"
           Loading="@_tableLoading.Value"
           Context="model"
           Size="@ClientConstant.DefaultTableSize"
           PaginationPosition="@ClientConstant.TablePaginationPosition"
           RemoteDataSource
           RowKey="x=>x.Id.ToString()">
        <TitleTemplate>
            <ResourceAuthorize ResourceKey="user_center_position_refresh">
                <TableSearch TDto="PositionDto" @ref="this._tableSearch" OnSearch="OnTableSearch" Settings="@_tableSearchSettings" CustomLocalizer="Localizer" />
            </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="user_center_position_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                            @Localizer[nameof(SharedLocalResource.DeleteSelected)]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="user_center_position_add">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnClickAdd">
                                    @Localizer[nameof(SharedLocalResource.Add)]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="user_center_position_refresh">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="reload" OnClick="ReLoadTable">
                                    @Localizer[nameof(SharedLocalResource.Refresh)]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <ColumnDefinitions>
            <Selection Hidden="@_userUnauthorizedResources["user_center_position_delete_selected"]" />
            <Column TData="string" Title="@Localizer[nameof(SharedLocalResource.Tenant)]" Hidden="@_userUnauthorizedResources[CommonResourceKeys.SystemTenantAdministratorKey]">
                <span>@model.Tenant?.Name</span>
            </Column>
            <PropertyColumn Property="x=>x.Name" Filterable />
            <PropertyColumn Property="x=>x.Duty" Filterable />
            <PropertyColumn Property="x=>x.Grade" Filterable Filters="positionGradeFilters">
                @{
                    var gradeCodeName = DictHelper.GetCodeNameFromCache<PositionDto>(() => model.Grade);
                    if (gradeCodeName != null)
                    {
                        gradeCodeName = Localizer[gradeCodeName];
                    }
                }
                <span>@(gradeCodeName)</span>
            </PropertyColumn>
            <PropertyColumn Property="x=>x.IsLocked" Filterable>
                <ResourceAuthorize ResourceKey="user_center_position_lock">
                    <Authorized>
                        <Switch @bind-Value="model.IsLocked" OnChange="e=>OnChangeIsLocked(model,e)" Loading="_lockBtnLoading[model]"></Switch>
                    </Authorized>
                    <NotAuthorized>
                        <TagYesNo Yes="model.IsLocked"></TagYesNo>
                    </NotAuthorized>
                </ResourceAuthorize>
            </PropertyColumn>
            <PropertyColumn Property="x=>x.CreatedTime" Format="@ClientConstant.DateTimeFormat" Sortable DefaultSortOrder="@SortDirection.Descending" />
            <ActionColumn>
                <Space>
                    <ResourceAuthorize ResourceKey="user_center_position_edit">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Edit)]" ArrowPointAtCenter="true">
                                <Button Icon="edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickEdit(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="user_center_position_detail">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Detail)]" ArrowPointAtCenter="true">
                                <Button Icon="eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="user_center_position_delete">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Delete)]" ArrowPointAtCenter="true">
                                <Button Icon="delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                </Space>
            </ActionColumn>
        </ColumnDefinitions>
    </Table>
</div>